"""
@Time ： 2022/11/28 10:01
@Auth ： 陈杰 200320501042
@E-mail : 1612845322@qq.com
"""
import os

existence = os.path.exists("d:\\test\\a.txt")
if existence:
    os.remove("d:\\test\\a.txt")
else:
    os.mkdir("d:\\test")

file = open("d:\\test\\a.txt","w+",encoding="utf-16")
line = input("请输入要写入的内容：")
file.write(line + "\n")
file.seek(0)
# print("文件{0}中的文本内容如下：".format(file.name))
# print(file.read())
# f = open("d:\\test\\a.txt","a")
# line = input("请输入要追加的内容：")
# file.write(line + "\n")
# file.seek(0)
# print("文件{0}中的文本内容如下：".format(file.name))
# print(file.read())
f = open("d:\\test\\a.txt","a",-1,"utf-16")
f.write("Hello Python!")
f.close()
f = open("d:\\test\\a.txt","r",-1,"utf-16")
for line in f:
    print(line)
file.close()